This scripts aggregate the mixed effect models
# d <- readRDS('E:/in_vivo_vr/sarah_glm_202006/time_model_data2plot.rds')
# Load a particular cohort
use_condaenv("glm_mec_model")
pd <- import("pandas")
pickle <-import("pickle")
cohort = c(2,3,4,5,7) # 2,3,4,5,7
#load all files
dfs = lst(n=5)
for (i in seq(5)){
file <- glue("/mnt/datastore/Teris/CurrentBiology_2022/cohort", cohort[[i]], "_df4r.pkl")
df <- pd$read_pickle(file)
df <- as_tibble(df)
dfs[[i]] = df
}
Warning in py_to_r.pandas.core.frame.DataFrame(result) :
index contains duplicated values: row names not set
Warning in py_to_r.pandas.core.frame.DataFrame(result) :
index contains duplicated values: row names not set
Warning in py_to_r.pandas.core.frame.DataFrame(result) :
index contains duplicated values: row names not set
Warning in py_to_r.pandas.core.frame.DataFrame(result) :
index contains duplicated values: row names not set
Warning in py_to_r.pandas.core.frame.DataFrame(result) :
index contains duplicated values: row names not set
df_ramp = as_tibble(pd$read_pickle("/mnt/datastore/Teris/CurrentBiology_2022/all_rampscore.pkl"))
Warning in py_to_r.pandas.core.frame.DataFrame(result) :
index contains duplicated values: row names not set
df <- bind_rows(dfs)
getFiringRate <- function(spiketrain){
spiketrain[[1]]/100
}
lm_cls <- read_tsv('/mnt/datastore/Teris/CurrentBiology_2022/all_results_coefficients.csv')
Rows: 1456 Columns: 11
── Column specification ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: "\t"
chr (6): session_id, unique_id, final_model_o_b, lm_group_b, lm_group_nb, lm_group_p
dbl (5): index, cluster_id, o_b_mod_coefs_pos, o_b_mod_coefs_speed, o_b_mod_coefs_accel
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
df_merged <- df %>% inner_join(lm_cls,by=c("session_id"="session_id","cluster_id"="cluster_id")) %>%
inner_join(df_ramp, by=c("session_id"="session_id","cluster_id"="cluster_id")) %>%
filter(ramp_region=="outbound", trial_type=="beaconed")
# Extract the firing rate
df_merged <- df_merged %>%
mutate(firingRate = map_dbl(spiketrain, getFiringRate)) %>%
mutate(trial_length_type = recode(trial_length_type, `0` = "Short", `1` = "Middle", `2` = "Long"))
included_sessions = unique(df$session_id)
df_merged
NA
Extrapolate firing rate at reward zone
Normalize the firing rate
getMaxFr <- function(data) {
max(data$firingRate)
}
# Get max firing rate of each cells
fr_max <- df_merged %>%
group_by(session_id, cluster_id) %>%
nest() %>%
mutate(max_fr = map_dbl(data,getMaxFr)) %>%
select(session_id, cluster_id, max_fr)
norm_data <- function(data){
data$firingRate <- data$firingRate/data$max_fr
return(data)
}
# Match back to the original
df_merged_norm <- df_merged %>%
inner_join(fr_max, by=c("session_id","cluster_id"))
df_merged_norm <- df_merged_norm %>%
group_by(session_id, cluster_id, trial_length_type) %>%
nest() %>%
mutate(data_norm = map(data, norm_data))
df_merged_filt <- df_merged_norm %>% filter(session_id=='M1_D31_2018-11-01_12-28-25', cluster_id==7)
print(df_merged_filt)
Fit a linear model with time and compare with the firing rate at the reward zone to see if it matches the time model
time_model <- function(data){
# print(names(data))
tidy(lm(firingRate ~ time_relative_outbound, data=data))
}
predict_reward_firingRate <- function(intercept, slope, trial_time){
slope*trial_time+intercept
}
find_reward_fringRate <- function(data){
last(data$firingRate)
}
fitSlopePeak <- function(row){
row %>% group_by(trial_number) %>%
nest() %>%
mutate(time_model = map(data, time_model)) %>%
mutate(intercept=map_dbl(time_model, ~ .x[[1, 'estimate']])) %>% #get intercept
mutate(slope = map_dbl(time_model, ~ .x[[2,'estimate']])) %>% #get slope
mutate(trial_time = map_dbl(data, ~last(.x$time_relative_outbound))) %>%
mutate(reward_fr = pmap_dbl(list(intercept,slope,trial_time),predict_reward_firingRate)) %>%
mutate(final_reward_fr = map_dbl(data,find_reward_fringRate)) %>%
group_by() %>%
summarize(mean_intercept=mean(intercept),
mean_slope = mean(slope),
mean_reward_fr = mean(reward_fr),
final_reward_fr = mean(final_reward_fr))
}
x2 <- df_merged_filt[1,]$data_norm[[1]]
fitSlopePeak(x2)
# get the predicted firing rate at the reward
data_merged_reward <- df_merged_norm %>% mutate(reward_fr_data = map(data_norm,possibly(fitSlopePeak,otherwise = NA))) %>%
unnest_wider(reward_fr_data)
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 41: trial_number = 164.
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 9: trial_number = 53.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 28: trial_number = 353.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 18: trial_number = 291.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 20: trial_number = 301.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 17: trial_number = 267.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 13: trial_number = 235.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 19: trial_number = 297.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 2: trial_number = 30.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 17: trial_number = 267.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 19: trial_number = 297.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 7: trial_number = 117.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 10: trial_number = 139.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 32: trial_number = 187.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 36: trial_number = 208.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 32: trial_number = 187.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 46: trial_number = 244.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 42: trial_number = 249.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 16: trial_number = 124.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 11: trial_number = 115.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 11: trial_number = 115.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 6: trial_number = 21.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 6: trial_number = 21.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 3: trial_number = 54.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 16: trial_number = 142.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 3: trial_number = 54.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 14: trial_number = 93.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 33: trial_number = 180.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 35: trial_number = 193.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 30: trial_number = 75.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 5: trial_number = 18.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 21: trial_number = 46.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 34: trial_number = 121.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 3: trial_number = 23.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 3: trial_number = 7.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 15: trial_number = 61.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 9: trial_number = 35.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 23: trial_number = 100.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 30: trial_number = 125.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 31: trial_number = 98.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 52: trial_number = 268.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 24: trial_number = 73.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 29: trial_number = 93.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 13: trial_number = 35.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 24: trial_number = 73.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 27: trial_number = 55.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 65: trial_number = 231.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 20: trial_number = 40.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 38: trial_number = 104.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 60: trial_number = 200.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 70: trial_number = 250.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 85: trial_number = 355.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 70: trial_number = 250.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 84: trial_number = 349.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 27: trial_number = 55.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 72: trial_number = 256.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 1: trial_number = 3.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 62: trial_number = 206.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 44: trial_number = 186.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 9: trial_number = 38.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 50: trial_number = 221.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 9: trial_number = 38.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 50: trial_number = 221.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 19: trial_number = 207.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 5: trial_number = 60.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 3: trial_number = 54.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 44: trial_number = 251.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 8: trial_number = 31.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 57: trial_number = 304.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 8: trial_number = 31.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 12: trial_number = 49.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 57: trial_number = 304.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 60: trial_number = 337.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 57: trial_number = 304.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 14: trial_number = 58.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 22: trial_number = 156.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 20: trial_number = 82.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 60: trial_number = 328.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 20: trial_number = 82.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 12: trial_number = 66.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 18: trial_number = 78.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 43: trial_number = 193.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 2: trial_number = 9.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 33: trial_number = 313.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 25: trial_number = 163.
Warning: Problem while computing `reward_fr_data = map(data_norm, possibly(fitSlopePeak, otherwise = NA))`.
ℹ essentially perfect fit: summary may be unreliable
ℹ The warning occurred in group 91: trial_number = 466.
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
New names:
* `` -> ...1
getLMcls <- function(data){
data$lm_group_b[[1]]
}
data2plot <- data_merged_reward %>%
filter(trial_length_type %in% c('Long','Short'))
data2plot$trial_length_type <- factor(data2plot$trial_length_type, levels=c('Long','Short'))
data2plot <- data2plot %>% mutate(cell_id = glue("{session_id}_{cluster_id}")) %>%
mutate(lm_group_b = map_chr(data, getLMcls))
# Simplify data for analysis
data_merged_reward_sel <- data2plot %>%
select(-data_norm, -data)
saveRDS(data_merged_reward_sel,'/mnt/datastore/Teris/CurrentBiology_2022/S5C_data2plot.rds', compress = FALSE)
# print(data_merged_reward_sel,n=3,width=300)
# options(repr.plot.width=8, repr.plot.height=15)
comp = list(c('Long','Short'))
p1 <- ggboxplot(data2plot, y='final_reward_fr',
x='trial_length_type',facet.by='lm_group_b', id = 'cell_id',
nrow=1, scales='free', xlab='Trial length', ylab='Intercept',
fill = "trial_length_type") +
labs(fill="Trial length") +
stat_compare_means(comparisons=comp,label = "p.signif",vjust=0.2, paired= TRUE, method='wilcox.test') +
theme_minimal(base_size=15)+
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),axis.line = element_line())
p2 <- ggboxplot(data2plot, y='mean_slope',
fill = "trial_length_type",
x='trial_length_type',facet.by='lm_group_b',
nrow=1,scales='free',xlab='Trial length',
ylab='Slope',id='cell_id') +
labs(fill="Trial length") +
stat_compare_means(comparisons=comp,label = "p.signif", paired= TRUE, vjust=0.2, method='wilcox.test') +
theme_minimal(base_size=15)+
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),axis.line = element_line())
p1 / p2
Warning: Removed 30 rows containing non-finite values (stat_boxplot).
Warning: Removed 30 rows containing non-finite values (stat_signif).
Warning: Removed 30 rows containing non-finite values (stat_boxplot).
Warning: Removed 30 rows containing non-finite values (stat_signif).
ggsave('paper_figures/S5C.pdf',width=12,height=8)
Warning: Removed 30 rows containing non-finite values (stat_boxplot).
Warning: Removed 30 rows containing non-finite values (stat_signif).
Warning: Removed 30 rows containing non-finite values (stat_boxplot).
Warning: Removed 30 rows containing non-finite values (stat_signif).
# ggboxplot(data2plot, y='mean_slope',color='trial_length_type',x='lm_result_outbound')
p1 <- ggboxplot(data2plot, y='final_reward_fr',
x='trial_length_type',facet.by='lm_group_b', id = 'cell_id',
nrow=1, scales='free', xlab='Trial length', ylab='Intercept',
fill = "trial_length_type") +
labs(fill="Trial length") +
stat_compare_means(comparisons=comp,label = "p.format",vjust=0.2, paired= TRUE, method='wilcox.test') +
theme_minimal(base_size=15)+
theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),axis.line = element_line())